home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 841 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: io.UWinnipeg.ca!wsimpson
  2. From: Bill Simpson <wsimpson@uwinnipeg.ca>
  3. Newsgroups: comp.lang.c
  4. Subject: warning: possibly incorrect assignment
  5. Date: Tue, 9 Jan 1996 09:26:35 -0600
  6. Organization: The University of Manitoba
  7. Message-ID: <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
  8. NNTP-Posting-Host: io.uwinnipeg.ca
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11.  
  12. I get the above warning when I compile code using the following
  13. function.  It flags the **** line.
  14.  
  15. void save_data(unsigned long int time[],int n)
  16.         {
  17.         char file_name[30];
  18.         double t;
  19.         int i;
  20.         FILE * fp;
  21.  
  22.         printf("Enter file name: ");
  23.         scanf("%s", file_name);
  24.  
  25. ****        while(fp=fopen(file_name,"r"))
  26.                 {
  27.                 printf("this file already exists--use another name\n");
  28.                 fclose(fp);
  29.                 printf("Enter filename:\n");
  30.                 scanf("%s", file_name);
  31.                 }
  32.  
  33.         fp=fopen(file_name,"w"); 
  34.         for (i=0;i<n;i++)
  35.                 {
  36.                 t=(double)time[i]/1000000; /*convert from microsec to sec*/
  37.                 fprintf(fp,"%.6f\n",t);
  38.                 }
  39.         fclose(fp);                         
  40.                                        
  41.         return;
  42.         }
  43.  
  44. How can I write this code so the compiler does not issue this warning?
  45. Please don't suggest I just tell the compiler to shut up.  In general
  46. the warnings are useful.  I do not want to just ignore the warning either.
  47. I have the FAQ and haven't seen this discussed.
  48.  
  49. (Any other improvements to above code segment welcomed)
  50.  
  51. Thanks very much for any help.
  52.  
  53. Bill Simpson
  54.